<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ranking
 *
 * @author user
 */

include_once 'inv_file.php';
include_once 'SC.php';

class ranking extends CI_Model {
    //put your code here
    
    public function compute($invfile,$lala){
        $arraySC=array();
        $arrayNoDoc=array();
        $ndoc=0;
        foreach ($invfile as $inv){
            $ndoc=sizeof($inv->weight);
            break;
        }
        for($i=0;$i<$ndoc;$i++){
            $item=array(
                "no"=>$i+1,
                "value"=>0
            );
            array_push($arraySC, $item);
        }
        
        foreach ($invfile as $inv){
            foreach ($lala as $la){
                if(($inv->the_term)==($la->the_term)){
                    $wq=$la->weight;
                    $arraydoc=$inv->weight;
                    for($j=1;$j<=sizeof($arraydoc);$j++){
                        $tempv=$arraydoc[$j]*$wq;
                        for($k=0;$k<sizeof($arraySC);$k++){
                            $tempSC=$arraySC[$k];
                            if($tempSC["no"]==$j){
                                $arraySC[$k]["value"]+=$tempv;
                                
                            }
                        }
                    }
                }
            }
        }
        $values=array();
        foreach ($arraySC as $asc){
            $values[] = $asc['value'];
        }
        array_multisort($values,SORT_DESC,$arraySC);
        foreach ($arraySC as $arSC){
            array_push($arrayNoDoc, $arSC["no"]);
        } 
        return $arrayNoDoc;
    }

    public function compute_all_sc($invfile,$lala){
        $arraySC=array();
        for($i = 1; $i <= sizeof($lala); ++$i){
            $item = $this->compute($invfile, $lala[$i]);
            array_push($arraySC, $item);
        }
        return $arraySC;
    }
   
    
}

?>
